package jtokyotyrant;

import java.util.List;
import java.util.Map;

public interface RDB {

	/** error code: success */
	int ESUCCESS = 0;
	/** error code: invalid operation */                            
	int EINVALID = 1;
	/** error code: host not found */
	int ENOHOST = 2;
	/** error code: connection refused */
	int EREFUSED = 3;
	/** error code: send error */
	int ESEND = 4;
	/** error code: recv error */
	int ERECV = 5;
	/** error code: existing record */
	int EKEEP = 6;
	/** error code: no record found */
	int ENOREC = 7;
	/** error code: miscellaneous error */
	int EMISC = 9999;


	/**tuning option: reconnect automatically */
	int TRECON = 1 << 0;

	/** scripting extension option: record locking */
	int XOLCKREC = 1 << 0;   
	/** scripting extension option: global locking */               
	int XOLCKGLB = 1 << 1;

	/** restore option: consistency checking*/
	int ROCHKCON = 1 << 0;

	/* miscellaneous operation option: omission of update log */
	int MONOULOG = 1 << 0;


	String errmsg(int ecode);
	int ecode();
	boolean tune(double timeoutSec, int opts);
	boolean open(String host, int port);
	boolean open(String serverExpr);
	boolean close();
	boolean put(byte[] key, byte[] value);
	boolean put(String key, String value);
	boolean putkeep(byte[] key, byte[] value);
	boolean putkeep(String key, String value);
	boolean putcat(byte[] key, byte[] value);
	boolean putcat(String key, String value);
	boolean putshl(byte[] key, byte[] value, int width);
	boolean putshl(String key, String value, int width);
	boolean putnr(byte[] key, byte[] value);
	boolean putnr(String key, String value);
	boolean out(byte[] key);
	boolean out(String key);
	byte[] get(byte[] key);
	String get(String key);
	/**
	 * @param recs specifies a map object containing the retrieval keys. 
	 *             As a result of this function, keys existing in the 
	 *             database have the corresponding values and keys not 
	 *             existing in the database are removed.
	 * @return If successful, the return value is the number of retrieved 
	 *         records or -1 on failure.
	 */
	int mget(Map<byte[], byte[]> recs);
	int mget2(Map<String, String> recs);
	int vsiz(byte[] key);
	int vsiz(String key);
	boolean iterinit();
	byte[] iternext();
	String iternext2();
	List<byte[]> fwmkeys(byte[] prefix, int max);
	List<String> fwmkeys(String prefix, int max);
	
	int addint(byte[] key, int num);
	int addint(String key, int num);
	double adddouble(byte[] key, double num);
	double adddouble(String key, double num);
	byte[] ext(String name, byte[] key, byte[] value, int opts);
	byte[] ext(String name, byte[] key, int opts);
	byte[] ext(String name, int opts);
	byte[] ext(String name, byte[] key, byte[] value);
	byte[] ext(String name, byte[] key);
	byte[] ext(String name);
	String ext2(String name, String key, String value, int opts);
	String ext2(String name, String key, int opts);
	String ext2(String name, int opts);
	String ext2(String name, String key, String value);
	String ext2(String name, String key);
	String ext2(String name);
	
	boolean sync();
	boolean optimize(String params);
	boolean vanish();
	boolean copy(String destfileOrCommand);
	boolean restore(String ulogDirectory, long tsMic, int opbs);
	boolean setmst(String host, int port, long tsMic, int opbs);
	boolean setmst(String serverExpr, long ts, int opbs);
	long rnum();
	long size();
	String stat();
	List<byte[]> misc(String funcName, byte[]... args);
	List<byte[]> misc(String funcName, int opts, byte[]... args);
	List<String> misc(String funcName, String... args);
	List<String> misc(String funcName, int opts, String... args);
}
